﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblQuoteDAO
    {
        private DBService _db = null;
        public TblQuoteDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public DataTable GetQuote(int JobID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select top 1 * from TblQuotes where JobID =@JobID order by QuoteID desc",
                    new string[] { "@JobID" },
                    new object[] { JobID }, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetQuoteLast(int JobID, string QuoteID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblQuotes where JobID = @JobID and QuoteID = @QuoteID",
                    new string[] { "@JobID", "@QuoteID" },
                    new object[] { JobID, QuoteID }, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable InsTblQuote(TblQuote tblQuote, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_TblQuotes_Ins",
                     new string[] { "@QuoteID", "@JobID", "@InspectionFee", "@AmountQuoted", "@DateQuoted", "@QuoteStatus", "@Notes", "@mode" },
                     new object[] {tblQuote.QuoteID, tblQuote.JobID, tblQuote.InspectionFee, tblQuote.AmountQuoted, tblQuote.DateQuoted, tblQuote.QuoteStatus, tblQuote.Notes, mode }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

    }
}
